package com.situ.springboot.config;

import com.situ.springboot.converter.String2DateConverter;
import com.situ.springboot.pojo.Admin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
// @Component    <bean>
// @Controller  @Service @Repository
// 这四个注解的作用是一样的，下面三个不一样主要是为了区分不同层

// @Configuration用于定义配置类，可以替换xml配置文件，
// 加了这个注解的类的内部包含一个或多个被@Bean注解的方法
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /* <bean name="admin" class="com.situ.springboot.pojo.Admin"/>*/
    @Bean
    public Admin createAdmin() {
        return new Admin();
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/D:/mypic/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter());
    }

    /*@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/page/login", "/admin/login", "/admin/logout", "/static/**");
    }*/
}
